
#ifndef  HELPER_SINGLETON_H
#define  HELPER_SINGLETON_H

namespace helper {

template <typename T>
class Singleton{
public:
    virtual ~Singleton(){}

    static T & instance(){
        static T t;
        __creater.do_nothing();
        return t;
    }

protected:
    Singleton(){}
private:
    struct CreaterBeforeMain {
        CreaterBeforeMain(){
            Singleton <T>::instance();
        }
        inline void do_nothing() const {}
    };
    static CreaterBeforeMain __creater;
};

template <typename T>
typename Singleton<T>::CreaterBeforeMain Singleton<T>::__creater;

} //end of namespace helper


#endif   /* HELPER_SINGLETON_H */
